package com.tjp.eight.ui.fragment.detail;

import com.tjp.eight.AllRetrofit;
import com.tjp.eight.ResultModel;
import com.tjp.eight.base.BasePresenterImpl;
import com.tjp.eight.constant.UrlConstant;
import com.tjp.eight.net.NetCallBack;
import com.tjp.eight.net.SubscribeCallBack;
import com.tjp.eight.ui.fragment.comment.ZanCommentResultModel;
import com.tjp.eight.ui.fragment.sub.SubResultModel;
import com.tjp.eight.utils.AppUtils;

import okhttp3.MediaType;
import okhttp3.RequestBody;

/**
 * Created by Administrator on 2017/2/15.
 */
public class ArticlePresenter extends BasePresenterImpl<DetaisView> {
    private DetailsService detailsService = AllRetrofit.getRetrofit(UrlConstant.BaseUrl).create(DetailsService.class);

    public ArticlePresenter(DetaisView detaisView) {
        attachView(detaisView);
    }

    public void loadData(String json) {
        RequestBody requestBody = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), json);
        addSubscription(detailsService.loadData(requestBody), new SubscribeCallBack<>(new NetCallBack<DetailModel>() {
            @Override
            public void onSuccess(DetailModel model) {
                view.loadData(model);
            }

            @Override
            public void onFails(int code, String msg) {
                view.loadFail(msg);
            }

            @Override
            public void onCompleted() {
                view.complite();
            }
        }));
    }

    public void sendComment(String json) {
        RequestBody requestBody = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), json);
        addSubscription(detailsService.sendComment(requestBody), new SubscribeCallBack<>(new NetCallBack<ResultModel>() {
            @Override
            public void onSuccess(ResultModel model) {
                view.sendComment(model);
            }

            @Override
            public void onFails(int code, String msg) {
                view.loadFail(msg);
            }

            @Override
            public void onCompleted() {
                view.complite();
            }
        }));
    }

    public void zanClick(String json) {
        RequestBody requestBody = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), json);
        addSubscription(detailsService.zanCDetail(requestBody), new SubscribeCallBack<>(new NetCallBack<ZanCommentResultModel>() {
            @Override
            public void onSuccess(ZanCommentResultModel model) {
                view.ZanResult(model);
            }

            @Override
            public void onFails(int code, String msg) {
                view.loadFail(msg);
            }

            @Override
            public void onCompleted() {
                view.complite();
            }
        }));
    }

    public void sub(String subJson) {
        RequestBody req = AppUtils.getRequestBody(subJson);
        addSubscription(detailsService.sub(req), new SubscribeCallBack<>(new NetCallBack<SubResultModel>() {
            @Override
            public void onSuccess(SubResultModel model) {
                view.subSuccess(model);
            }

            @Override
            public void onFails(int code, String msg) {
                view.loadFail(msg);
            }

            @Override
            public void onCompleted() {

            }
        }));
    }

    public void getShareData(String shareJson) {
        RequestBody requestBody = AppUtils.getRequestBody(shareJson);
        addSubscription(detailsService.getShareData(requestBody), new SubscribeCallBack(new NetCallBack<ShareModel>() {
            @Override
            public void onSuccess(ShareModel model) {
                view.getShareDataSuccess(model);
            }

            @Override
            public void onFails(int code, String msg) {
                view.loadFail(msg);
            }

            @Override
            public void onCompleted() {

            }
        }));
    }

    public void collcetion(String cpJson) {
        RequestBody req = AppUtils.getRequestBody(cpJson);
        addSubscription(detailsService.collection(req),new SubscribeCallBack<>(new NetCallBack<CollectionRModel>() {
            @Override
            public void onSuccess(CollectionRModel model) {
                view.collectionSuccess(model);
            }

            @Override
            public void onFails(int code, String msg) {
                view.loadFail(msg);
            }

            @Override
            public void onCompleted() {

            }
        }));
    }

    public void azan(String praise) {
        RequestBody req = AppUtils.getRequestBody(praise);
        addSubscription(detailsService.azan(req),new SubscribeCallBack<>(new NetCallBack<ResultModel>() {
            @Override
            public void onSuccess(ResultModel model) {
                view.zanSuccess(model);
            }

            @Override
            public void onFails(int code, String msg) {
                view.loadFail(msg);
            }

            @Override
            public void onCompleted() {

            }
        }));
    }
    public void weak(String praise) {
        RequestBody req = AppUtils.getRequestBody(praise);
        addSubscription(detailsService.weak(req),new SubscribeCallBack<>(new NetCallBack<ResultModel>() {
            @Override
            public void onSuccess(ResultModel model) {
                view.weakSuccess(model);
            }

            @Override
            public void onFails(int code, String msg) {
                view.loadFail(msg);
            }

            @Override
            public void onCompleted() {

            }
        }));
    }

    public void shareSuccess(String shareRJson) {
        RequestBody req = AppUtils.getRequestBody(shareRJson);
        addSubscription(detailsService.sharesuccess(req), new SubscribeCallBack<>(new NetCallBack<ResultModel>() {
            @Override
            public void onSuccess(ResultModel model) {
                view.shareSuccess(model);
            }

            @Override
            public void onFails(int code, String msg) {
                view.loadFail(msg);
            }

            @Override
            public void onCompleted() {

            }
        }));
    }
}
